<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <title>std.stdio</title>
  <link href="./css/style.css" rel="stylesheet" type="text/css"/>
  <!-- <link href="./img/icon.png" rel="icon" type="image/png"/> -->
  <script type="text/javascript" src="./js/jquery.js"></script>
  <script type="text/javascript" src="./js/modules.js"></script>
  <script type="text/javascript" src="./js/quicksearch.js"></script>
  <script type="text/javascript" src="./js/navigation.js"></script>
  <!--<script type="text/javascript" src="./js/jquery.treeview.js"></script>-->
  <script type="text/javascript">
    var g_moduleFQN = "std.stdio";
  </script>
  
</head>
<body>
<div id="content">
  <h1><a href="./htmlsrc/std.stdio.html" class="symbol">std.stdio</a></h1>
  
<div class="summary">Standard I/O functions that extend <b>std.c.stdio</b>.
 <b>std.c.stdio</b> is <span class="d_param">public</span>ally imported when importing
 <b>std.stdio</b>.</div>
<p class="sec_header">Authors:</p><a href="http://digitalmars.com">Walter Bright</a>, <a href="http://erdani.org">Andrei
Alexandrescu</a>
<dl>
<dt class="decl">int <a class="symbol _function" name="fputc_unlocked" href="./htmlsrc/std.stdio.html#L89" kind="function" beg="89" end="89">fputc_unlocked</a><span class="params">(int, FILE*)</span>; <span class="attrs">[<span class="linkg">extern(C)</span>]</span> <a title="Permalink to this symbol" href="#fputc_unlocked" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L89">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">int <a class="symbol _function" name="fputwc_unlocked" href="./htmlsrc/std.stdio.html#L90" kind="function" beg="90" end="90">fputwc_unlocked</a><span class="params">(wchar_t, FILE*)</span>; <span class="attrs">[<span class="linkg">extern(C)</span>]</span> <a title="Permalink to this symbol" href="#fputwc_unlocked" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L90">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">int <a class="symbol _function" name="fgetc_unlocked" href="./htmlsrc/std.stdio.html#L91" kind="function" beg="91" end="91">fgetc_unlocked</a><span class="params">(FILE*)</span>; <span class="attrs">[<span class="linkg">extern(C)</span>]</span> <a title="Permalink to this symbol" href="#fgetc_unlocked" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L91">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">int <a class="symbol _function" name="fgetwc_unlocked" href="./htmlsrc/std.stdio.html#L92" kind="function" beg="92" end="92">fgetwc_unlocked</a><span class="params">(FILE*)</span>; <span class="attrs">[<span class="linkg">extern(C)</span>]</span> <a title="Permalink to this symbol" href="#fgetwc_unlocked" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L92">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">void <a class="symbol _function" name="flockfile" href="./htmlsrc/std.stdio.html#L93" kind="function" beg="93" end="93">flockfile</a><span class="params">(FILE*)</span>; <span class="attrs">[<span class="linkg">extern(C)</span>]</span> <a title="Permalink to this symbol" href="#flockfile" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L93">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">void <a class="symbol _function" name="funlockfile" href="./htmlsrc/std.stdio.html#L94" kind="function" beg="94" end="94">funlockfile</a><span class="params">(FILE*)</span>; <span class="attrs">[<span class="linkg">extern(C)</span>]</span> <a title="Permalink to this symbol" href="#funlockfile" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L94">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">ssize_t <a class="symbol _function" name="getline" href="./htmlsrc/std.stdio.html#L95" kind="function" beg="95" end="95">getline</a><span class="params">(char**, size_t*, FILE*)</span>; <span class="attrs">[<span class="linkg">extern(C)</span>]</span> <a title="Permalink to this symbol" href="#getline" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L95">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">ssize_t <a class="symbol _function" name="getdelim" href="./htmlsrc/std.stdio.html#L96" kind="function" beg="96" end="96">getdelim</a><span class="params">(char**, size_t*, int, FILE*)</span>; <span class="attrs">[<span class="linkg">extern(C)</span>]</span> <a title="Permalink to this symbol" href="#getdelim" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L96">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">size_t <a class="symbol _function" name="fwrite_unlocked" href="./htmlsrc/std.stdio.html#L98" kind="function" beg="98" end="99">fwrite_unlocked</a><span class="params">(const( void)* <em>ptr</em>, size_t <em>size</em>, size_t <em>n</em>, FILE * <em>stream</em>)</span>; <span class="attrs">[<span class="prot">private</span>, <span class="linkg">extern(C)</span>]</span> <a title="Permalink to this symbol" href="#fwrite_unlocked" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L98">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">alias fputc_unlocked <a class="symbol _alias" name="FPUTC" href="./htmlsrc/std.stdio.html#L102" kind="alias" beg="102" end="102">FPUTC</a>; <a title="Permalink to this symbol" href="#FPUTC" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L102">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">alias fputwc_unlocked <a class="symbol _alias" name="FPUTWC" href="./htmlsrc/std.stdio.html#L103" kind="alias" beg="103" end="103">FPUTWC</a>; <a title="Permalink to this symbol" href="#FPUTWC" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L103">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">alias fgetc_unlocked <a class="symbol _alias" name="FGETC" href="./htmlsrc/std.stdio.html#L104" kind="alias" beg="104" end="104">FGETC</a>; <a title="Permalink to this symbol" href="#FGETC" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L104">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">alias fgetwc_unlocked <a class="symbol _alias" name="FGETWC" href="./htmlsrc/std.stdio.html#L105" kind="alias" beg="105" end="105">FGETWC</a>; <a title="Permalink to this symbol" href="#FGETWC" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L105">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">alias flockfile <a class="symbol _alias" name="FLOCK" href="./htmlsrc/std.stdio.html#L107" kind="alias" beg="107" end="107">FLOCK</a>; <a title="Permalink to this symbol" href="#FLOCK" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L107">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">alias funlockfile <a class="symbol _alias" name="FUNLOCK" href="./htmlsrc/std.stdio.html#L108" kind="alias" beg="108" end="108">FUNLOCK</a>; <a title="Permalink to this symbol" href="#FUNLOCK" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L108">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">class <a class="symbol _class" name="StdioException" href="./htmlsrc/std.stdio.html#L119" kind="class" beg="119" end="150">StdioException</a> : Exception; <a title="Permalink to this symbol" href="#StdioException" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L119">#</a></dt>
<dd class="ddef">
<div class="summary">Thrown if I/O errors happen.</div>
<dl>
<dt class="decl">uint <a class="symbol _variable" name="StdioException.errno" href="./htmlsrc/std.stdio.html#L121" kind="variable" beg="121" end="121">errno</a>; <a title="Permalink to this symbol" href="#StdioException.errno" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L121">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl"><a class="symbol _ctor" name="StdioException.this" href="./htmlsrc/std.stdio.html#L123" kind="ctor" beg="123" end="126">this</a><span class="params">(string <em>msg</em>)</span>; <a title="Permalink to this symbol" href="#StdioException.this" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L123">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl"><a class="symbol _ctor" name="StdioException.this:2" href="./htmlsrc/std.stdio.html#L128" kind="ctor" beg="128" end="139">this</a><span class="params">(uint <em>errno</em>)</span>; <a title="Permalink to this symbol" href="#StdioException.this:2" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L128">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">void <a class="symbol _function" name="StdioException.opCall" href="./htmlsrc/std.stdio.html#L141" kind="function" beg="141" end="144">opCall</a><span class="params">(string <em>msg</em>)</span>; <span class="attrs">[<span class="stc">static</span>]</span> <a title="Permalink to this symbol" href="#StdioException.opCall" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L141">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">void <a class="symbol _function" name="StdioException.opCall:2" href="./htmlsrc/std.stdio.html#L146" kind="function" beg="146" end="149">opCall</a><span class="params">()</span>; <span class="attrs">[<span class="stc">static</span>]</span> <a title="Permalink to this symbol" href="#StdioException.opCall:2" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L146">#</a></dt>
<dd class="ddef"></dd></dl></dd>
<dt class="decl">void <a class="symbol _function" name="writefx" href="./htmlsrc/std.stdio.html#L153" kind="function" beg="153" end="220">writefx</a><span class="params">(FILE* <em>fp</em>, TypeInfo[] <em>arguments</em>, void* <em>argptr</em>, int <em>newline</em> = false)</span>; <span class="attrs">[<span class="prot">private</span>]</span> <a title="Permalink to this symbol" href="#writefx" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L153">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">void <a class="symbol _function" name="write" href="./htmlsrc/std.stdio.html#L237" kind="function" beg="237" end="253">write</a><span class="tparams">(T...)</span><span class="params">(T <em>args</em>)</span>; <a title="Permalink to this symbol" href="#write" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L237">#</a></dt>
<dd class="ddef">
<div class="summary">If the first argument <span class="d_param">args[0]</span> is a <span class="d_param">FILE*</span>, for
 each argument <span class="d_param">arg</span> in <span class="d_param">args[1..$]</span>, format the
 argument (as per <a href="std_conv.html">to!(string)(arg)</a>) and
 write the resulting string to <span class="d_param">args[0]</span>. If <span class="d_param">
 args[0]</span> is not a <span class="d_param">FILE*</span>, the call is equivalent to
 <span class="d_param">write(stdout, args)</span>.</div>
A call without any arguments will fail to compile. In the
 exceedingly rare case you'd want to print a <span class="d_param">FILE*</span> to
 <span class="d_param">stdout</span> as a hex pointer, <span class="d_param">write("", myFilePtr)</span>
 will do the trick.
<p class="bl"/>
 In case of an I/O error, throws an StdioException.</dd>
<dt class="decl"><a class="symbol _unittest" name="unittest" href="./htmlsrc/std.stdio.html#L255" kind="unittest" beg="255" end="277">unittest</a>; <a title="Permalink to this symbol" href="#unittest" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L255">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">void <a class="symbol _function" name="writeln" href="./htmlsrc/std.stdio.html#L284" kind="function" beg="284" end="287">writeln</a><span class="tparams">(T...)</span><span class="params">(T <em>args</em>)</span>; <a title="Permalink to this symbol" href="#writeln" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L284">#</a></dt>
<dd class="ddef">
<div class="summary">Equivalent to <span class="d_param">write(args, '\n')</span>.  Calling <span class="d_param">
 writeln</span> without arguments is valid and just prints a newline to
 the standard output.</div></dd>
<dt class="decl"><a class="symbol _unittest" name="unittest:2" href="./htmlsrc/std.stdio.html#L289" kind="unittest" beg="289" end="313">unittest</a>; <a title="Permalink to this symbol" href="#unittest:2" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L289">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">void <a class="symbol _function" name="writef" href="./htmlsrc/std.stdio.html#L357" kind="function" beg="357" end="386">writef</a><span class="tparams">(T...)</span><span class="params">(T <em>args</em>)</span>; <a title="Permalink to this symbol" href="#writef" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L357">#</a></dt>
<dd class="ddef">
<div class="summary">If the first argument <span class="d_param">args[0]</span> is a <span class="d_param">FILE*</span>, use
 <a href="std_format.html#format-string">the format specifier</a> in
 <span class="d_param">args[1]</span> to control the formatting of <span class="d_param">
 args[2..$]</span>, and write the resulting string to <span class="d_param">args[0]</span>.
 If <span class="d_param">arg[0]</span> is not a <span class="d_param">FILE*</span>, the call is
 equivalent to <span class="d_param">writef(stdout, args)</span>.</div>
<p class="sec_header">IMPORTANT:</p>New behavior starting with D 2.006: unlike previous versions,
<span class="d_param">writef</span> (and also <span class="d_param">writefln</span>) only scans its first
string argument for format specifiers, but not subsequent string
arguments. This decision was made because the old behavior made it
unduly hard to simply print string variables that occasionally
embedded percent signs.
<p class="bl"/>
Also new starting with 2.006 is support for positional
parameters with
<a href="http://opengroup.org/onlinepubs/009695399/functions/printf.html">
POSIX</a> syntax.
<p class="sec_header">Example:</p><pre class="d_code">
<span class="i">writef</span>(<span class="sl">"Date: %2$s %1$s"</span>, <span class="sl">"October"</span>, <span class="n">5</span>); <span class="lc">// "Date: 5 October"</span>
</pre>
<p class="bl"/>
The positional and non-positional styles can be mixed in the same
format string. (POSIX leaves this behavior undefined.) The internal
counter for non-positional parameters tracks the next parameter after
the largest positional parameter already used.
<p class="bl"/>
New starting with 2.008: raw format specifiers. Using the "%r"
specifier makes <span class="d_param">writef</span> simply write the binary
representation of the argument. Use "%-r" to write numbers in little
endian format, "%+r" to write numbers in big endian format, and "%r"
to write numbers in platform-native format.</dd>
<dt class="decl"><a class="symbol _unittest" name="unittest:3" href="./htmlsrc/std.stdio.html#L388" kind="unittest" beg="388" end="406">unittest</a>; <a title="Permalink to this symbol" href="#unittest:3" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L388">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">void <a class="symbol _function" name="writefln" href="./htmlsrc/std.stdio.html#L411" kind="function" beg="411" end="414">writefln</a><span class="tparams">(T...)</span><span class="params">(T <em>args</em>)</span>; <a title="Permalink to this symbol" href="#writefln" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L411">#</a></dt>
<dd class="ddef">
<div class="summary">Equivalent to <span class="d_param">writef(args, '\n')</span>.</div></dd>
<dt class="decl"><a class="symbol _unittest" name="unittest:4" href="./htmlsrc/std.stdio.html#L416" kind="unittest" beg="416" end="447">unittest</a>; <a title="Permalink to this symbol" href="#unittest:4" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L416">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">void <a class="symbol _function" name="fwritef" href="./htmlsrc/std.stdio.html#L452" kind="function" beg="452" end="455">fwritef</a><span class="params">(FILE* <em>fp</em>, ...)</span>; <a title="Permalink to this symbol" href="#fwritef" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L452">#</a></dt>
<dd class="ddef">
<div class="summary">Kept for backward compatibility. Use <span class="d_param">writef</span> instead.</div></dd>
<dt class="decl">void <a class="symbol _function" name="fwritefln" href="./htmlsrc/std.stdio.html#L460" kind="function" beg="460" end="463">fwritefln</a><span class="params">(FILE* <em>fp</em>, ...)</span>; <a title="Permalink to this symbol" href="#fwritefln" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L460">#</a></dt>
<dd class="ddef">
<div class="summary">Kept for backward compatibility. Use <span class="d_param">writefln</span> instead.</div></dd>
<dt class="decl">string <a class="symbol _function" name="readln" href="./htmlsrc/std.stdio.html#L489" kind="function" beg="489" end="494">readln</a><span class="params">(FILE* <em>fp</em> = stdin, dchar <em>terminator</em> = '\n')</span>; <a title="Permalink to this symbol" href="#readln" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L489">#</a></dt>
<dd class="ddef">
<div class="summary">Read line from stream <span class="d_param">fp</span>.</div>
<p class="sec_header">Returns:</p><span class="d_param">null</span> for end of file,
        <span class="d_param">char[]</span> for line read from <span class="d_param">fp</span>, including terminating character
<p class="sec_header">Params:</p>
<table class="params">
<tr><td><em></em></td><td><span class="d_param">fp</span> = input stream
        <span class="d_param">terminator</span> = line terminator, '\n' by default</td></tr></table>
<p class="sec_header">Throws:</p><span class="d_param">StdioException</span> on error
<p class="sec_header">Example:</p>Reads <span class="d_param">stdin</span> and writes it to <span class="d_param">stdout</span>.
<pre class="d_code">
<span class="k">import</span> <span class="i">std</span>.<span class="i">stdio</span>;

<span class="k">int</span> <span class="i">main</span>()
{
    <span class="k">char</span>[] <span class="i">buf</span>;
    <span class="k">while</span> ((<span class="i">buf</span> = <span class="i">readln</span>()) != <span class="k">null</span>)
        <span class="i">write</span>(<span class="i">buf</span>);
    <span class="k">return</span> <span class="n">0</span>;
}
</pre></dd>
<dt class="decl">size_t <a class="symbol _function" name="readln:2" href="./htmlsrc/std.stdio.html#L530" kind="function" beg="530" end="764">readln</a><span class="params">(FILE* <em>fp</em>, inout char[] <em>buf</em>, dchar <em>terminator</em> = '\n')</span>; <a title="Permalink to this symbol" href="#readln:2" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L530">#</a></dt>
<dt class="decl">size_t <a class="symbol _function" name="readln:3" href="./htmlsrc/std.stdio.html#L767" kind="function" beg="767" end="770">readln</a><span class="params">(inout char[] <em>buf</em>, dchar <em>terminator</em> = '\n')</span>; <a title="Permalink to this symbol" href="#readln:3" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L767">#</a></dt>
<dt class="decl">size_t <a class="symbol _function" name="readln:4" href="./htmlsrc/std.stdio.html#L774" kind="function" beg="774" end="784">readln</a><span class="params">(FILE* <em>f</em>, inout wchar[] <em>buf</em>, dchar <em>terminator</em> = '\n')</span>; <a title="Permalink to this symbol" href="#readln:4" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L774">#</a></dt>
<dt class="decl">size_t <a class="symbol _function" name="readln:5" href="./htmlsrc/std.stdio.html#L788" kind="function" beg="788" end="798">readln</a><span class="params">(FILE* <em>f</em>, inout dchar[] <em>buf</em>, dchar <em>terminator</em> = '\n')</span>; <a title="Permalink to this symbol" href="#readln:5" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L788">#</a></dt>
<dd class="ddef">
<div class="summary">Read line from stream <span class="d_param">fp</span> and write it to <span class="d_param">
 buf[]</span>, including terminating character.</div>
This is often faster than <span class="d_param">readln(FILE*)</span> because the buffer
 is reused each call. Note that reusing the buffer means that
 the previous contents of it need to be copied if needed.
<p class="sec_header">Params:</p>
<table class="params">
<tr><td><em>is</em></td><td><span class="d_param">fp</span> = input stream
        <span class="d_param">buf</span> = buffer used to store the resulting line data. buf
                is resized as necessary.</td></tr></table>
<p class="sec_header">Returns:</p>0 for end of file, otherwise
        number of characters read
<p class="sec_header">Throws:</p><span class="d_param">StdioException</span> on error
<p class="sec_header">Example:</p>Reads <span class="d_param">stdin</span> and writes it to <span class="d_param">stdout</span>.
<pre class="d_code">
<span class="k">import</span> <span class="i">std</span>.<span class="i">stdio</span>;

<span class="k">int</span> <span class="i">main</span>()
{
    <span class="k">char</span>[] <span class="i">buf</span>;
    <span class="k">while</span> (<span class="i">readln</span>(<span class="i">stdin</span>, <span class="i">buf</span>))
        <span class="i">write</span>(<span class="i">buf</span>);
    <span class="k">return</span> <span class="n">0</span>;
}
</pre>
This method is more efficient than the one in the previous example
because <span class="d_param">readln(stdin, buf)</span> reuses (if possible) memory
allocated by <span class="d_param">buf</span>, whereas <span class="d_param">buf = readln()</span> makes a
new memory allocation with every line.</dd>
<dt class="decl">FILE* <a class="symbol _function" name="fopen" href="./htmlsrc/std.stdio.html#L804" kind="function" beg="804" end="819">fopen</a><span class="params">(in char[] <em>name</em>, in char[] <em>mode</em> = "r")</span>; <a title="Permalink to this symbol" href="#fopen" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L804">#</a></dt>
<dd class="ddef">
<div class="summary">Convenience function that forwards to <span class="d_param">std.c.stdio.fopen</span>
 with appropriately-constructed C-style strings.</div></dd>
<dt class="decl">FILE* <a class="symbol _function" name="popen" href="./htmlsrc/std.stdio.html#L823" kind="function" beg="823" end="823">popen</a><span class="params">(const char*, const char*)</span>; <span class="attrs">[<span class="linkg">extern(C)</span>]</span> <a title="Permalink to this symbol" href="#popen" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L823">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">FILE* <a class="symbol _function" name="popen:2" href="./htmlsrc/std.stdio.html#L829" kind="function" beg="829" end="832">popen</a><span class="params">(in char[] <em>name</em>, in char[] <em>mode</em> = "r")</span>; <a title="Permalink to this symbol" href="#popen:2" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L829">#</a></dt>
<dd class="ddef">
<div class="summary">Convenience function that forwards to <span class="d_param">std.c.stdio.popen</span>
 with appropriately-constructed C-style strings.</div></dd>
<dt class="decl">void <a class="symbol _function" name="binaryWrite" href="./htmlsrc/std.stdio.html#L839" kind="function" beg="839" end="843">binaryWrite</a><span class="tparams">(T)</span><span class="params">(FILE* <em>f</em>, T <em>obj</em>)</span>; <span class="attrs">[<span class="prot">private</span>]</span> <a title="Permalink to this symbol" href="#binaryWrite" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L839">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">struct <a class="symbol _struct" name="PrivateFileWriter" href="./htmlsrc/std.stdio.html#L854" kind="struct" beg="854" end="956">PrivateFileWriter</a><span class="tparams">(Char)</span>; <a title="Permalink to this symbol" href="#PrivateFileWriter" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L854">#</a></dt>
<dd class="ddef">
<dl>
<dt class="decl">alias Char <a class="symbol _alias" name="PrivateFileWriter.NativeChar" href="./htmlsrc/std.stdio.html#L856" kind="alias" beg="856" end="856">NativeChar</a>; <a title="Permalink to this symbol" href="#PrivateFileWriter.NativeChar" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L856">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">FILE* <a class="symbol _variable" name="PrivateFileWriter.backend" href="./htmlsrc/std.stdio.html#L857" kind="variable" beg="857" end="857">backend</a>; <a title="Permalink to this symbol" href="#PrivateFileWriter.backend" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L857">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">int <a class="symbol _variable" name="PrivateFileWriter.orientation" href="./htmlsrc/std.stdio.html#L858" kind="variable" beg="858" end="858">orientation</a>; <a title="Permalink to this symbol" href="#PrivateFileWriter.orientation" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L858">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">void <a class="symbol _function" name="PrivateFileWriter.write" href="./htmlsrc/std.stdio.html#L860" kind="function" beg="860" end="880">write</a><span class="tparams">(C)</span><span class="params">(in C[] <em>s</em>)</span>; <a title="Permalink to this symbol" href="#PrivateFileWriter.write" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L860">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">void <a class="symbol _function" name="PrivateFileWriter.putchar" href="./htmlsrc/std.stdio.html#L882" kind="function" beg="882" end="955">putchar</a><span class="tparams">(C)</span><span class="params">(in C <em>c</em>)</span>; <a title="Permalink to this symbol" href="#PrivateFileWriter.putchar" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L882">#</a></dt>
<dd class="ddef"></dd></dl></dd>
<dt class="decl">struct <a class="symbol _struct" name="lines" href="./htmlsrc/std.stdio.html#L1003" kind="struct" beg="1003" end="1115">lines</a>; <a title="Permalink to this symbol" href="#lines" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L1003">#</a></dt>
<dd class="ddef">
<div class="summary">Iterates through the lines of a file by using <span class="d_param">foreach</span>.</div>
<p class="sec_header">Example:</p><pre class="d_code">
<span class="k">void</span> <span class="i">main</span>()
{
  <span class="k">foreach</span> (<span class="i">string</span> <span class="i">line</span>; <span class="i">lines</span>(<span class="i">stdin</span>))
  {
    ... <span class="i">use</span> <span class="i">line</span> ...
  }
}
</pre>
 The line terminator ('\n' by default) is part of the string read (it
could be missing in the last line of the file). Several types are
supported for <span class="d_param">line</span>, and the behavior of <span class="d_param">lines</span>
changes accordingly:
<p class="bl"/>
<ol><li>If <span class="d_param">line</span> has type <span class="d_param">string</span>, <span class="d_param">
wstring</span>, or <span class="d_param">dstring</span>, a new string of the respective type
is allocated every read.</li> <li>If <span class="d_param">line</span> has type <span class="d_param">
char[]</span>, <span class="d_param">wchar[]</span>, <span class="d_param">dchar[]</span>, the line's content
will be reused (overwritten) across reads.</li> <li>If <span class="d_param">line</span>
has type <span class="d_param">invariant(ubyte)[]</span>, the behavior is similar to
case (1), except that no UTF checking is attempted upon input.</li> <li>
If <span class="d_param">line</span> has type <span class="d_param">ubyte[]</span>, the behavior is
similar to case (2), except that no UTF checking is attempted upon
input.</li></ol>
<p class="bl"/>
In all cases, a two-symbols versions is also accepted, in which case
the first symbol (of integral type, e.g. <span class="d_param">ulong</span> or <span class="d_param">
uint</span>) tracks the zero-based number of the current line.
<p class="sec_header">Example:</p><pre class="d_code">
<span class="k">foreach</span> (<span class="k">ulong</span> <span class="i">i</span>, <span class="i">string</span> <span class="i">line</span>; <span class="i">lines</span>(<span class="i">stdin</span>))
{
  ... <span class="i">use</span> <span class="i">line</span> ...
}
</pre>
<p class="bl"/>
 In case of an I/O error, an <span class="d_param">StdioException</span> is thrown.
<dl>
<dt class="decl">FILE * <a class="symbol _variable" name="lines.f" href="./htmlsrc/std.stdio.html#L1005" kind="variable" beg="1005" end="1005">f</a>; <span class="attrs">[<span class="prot">private</span>]</span> <a title="Permalink to this symbol" href="#lines.f" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L1005">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">dchar <a class="symbol _variable" name="lines.terminator" href="./htmlsrc/std.stdio.html#L1006" kind="variable" beg="1006" end="1006">terminator</a>; <span class="attrs">[<span class="prot">private</span>]</span> <a title="Permalink to this symbol" href="#lines.terminator" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L1006">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">string <a class="symbol _variable" name="lines.fileName" href="./htmlsrc/std.stdio.html#L1007" kind="variable" beg="1007" end="1007">fileName</a>; <span class="attrs">[<span class="prot">private</span>]</span> <a title="Permalink to this symbol" href="#lines.fileName" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L1007">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">lines <a class="symbol _function" name="lines.opCall" href="./htmlsrc/std.stdio.html#L1009" kind="function" beg="1009" end="1015">opCall</a><span class="params">(FILE* <em>f</em>, dchar <em>terminator</em> = '\n')</span>; <span class="attrs">[<span class="stc">static</span>]</span> <a title="Permalink to this symbol" href="#lines.opCall" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L1009">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">int <a class="symbol _function" name="lines.opApply" href="./htmlsrc/std.stdio.html#L1029" kind="function" beg="1029" end="1072">opApply</a><span class="tparams">(D)</span><span class="params">(D <em>dg</em>)</span>; <a title="Permalink to this symbol" href="#lines.opApply" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L1029">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">int <a class="symbol _function" name="lines.opApplyRaw" href="./htmlsrc/std.stdio.html#L1074" kind="function" beg="1074" end="1114">opApplyRaw</a><span class="tparams">(D)</span><span class="params">(D <em>dg</em>)</span>; <a title="Permalink to this symbol" href="#lines.opApplyRaw" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L1074">#</a></dt>
<dd class="ddef"></dd></dl></dd>
<dt class="decl"><a class="symbol _unittest" name="unittest:5" href="./htmlsrc/std.stdio.html#L1117" kind="unittest" beg="1117" end="1224">unittest</a>; <a title="Permalink to this symbol" href="#unittest:5" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L1117">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">struct <a class="symbol _struct" name="chunks" href="./htmlsrc/std.stdio.html#L1250" kind="struct" beg="1250" end="1304">chunks</a>; <a title="Permalink to this symbol" href="#chunks" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L1250">#</a></dt>
<dd class="ddef">
<div class="summary">Iterates through a file a chunk at a time by using <span class="d_param">
foreach</span>.</div>
<p class="sec_header">Example:</p><pre class="d_code">
<span class="k">void</span> <span class="i">main</span>()
{
  <span class="k">foreach</span> (<span class="k">ubyte</span>[] <span class="i">buffer</span>; <span class="i">chunks</span>(<span class="i">stdin</span>, <span class="n">4096</span>))
  {
    ... <span class="i">use</span> <span class="i">buffer</span> ...
  }
}
</pre>
<p class="bl"/>
The content of <span class="d_param">buffer</span> is reused across calls. In the
 example above, <span class="d_param">buffer.length</span> is 4096 for all iterations,
 except for the last one, in which case <span class="d_param">buffer.length</span> may
 be less than 4096 (but always greater than zero).
<p class="bl"/>
 In case of an I/O error, an <span class="d_param">StdioException</span> is thrown.
<dl>
<dt class="decl">FILE* <a class="symbol _variable" name="chunks.f" href="./htmlsrc/std.stdio.html#L1252" kind="variable" beg="1252" end="1252">f</a>; <span class="attrs">[<span class="prot">private</span>]</span> <a title="Permalink to this symbol" href="#chunks.f" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L1252">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">size_t <a class="symbol _variable" name="chunks.size" href="./htmlsrc/std.stdio.html#L1253" kind="variable" beg="1253" end="1253">size</a>; <span class="attrs">[<span class="prot">private</span>]</span> <a title="Permalink to this symbol" href="#chunks.size" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L1253">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">string <a class="symbol _variable" name="chunks.fileName" href="./htmlsrc/std.stdio.html#L1254" kind="variable" beg="1254" end="1254">fileName</a>; <span class="attrs">[<span class="prot">private</span>]</span> <a title="Permalink to this symbol" href="#chunks.fileName" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L1254">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">chunks <a class="symbol _function" name="chunks.opCall" href="./htmlsrc/std.stdio.html#L1256" kind="function" beg="1256" end="1263">opCall</a><span class="params">(FILE* <em>f</em>, size_t <em>size</em>)</span>; <span class="attrs">[<span class="stc">static</span>]</span> <a title="Permalink to this symbol" href="#chunks.opCall" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L1256">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">int <a class="symbol _function" name="chunks.opApply" href="./htmlsrc/std.stdio.html#L1274" kind="function" beg="1274" end="1303">opApply</a><span class="tparams">(D)</span><span class="params">(D <em>dg</em>)</span>; <a title="Permalink to this symbol" href="#chunks.opApply" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L1274">#</a></dt>
<dd class="ddef"></dd></dl></dd>
<dt class="decl"><a class="symbol _unittest" name="unittest:6" href="./htmlsrc/std.stdio.html#L1306" kind="unittest" beg="1306" end="1332">unittest</a>; <a title="Permalink to this symbol" href="#unittest:6" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/std.stdio.html#L1306">#</a></dt>
<dd class="ddef"></dd></dl>
</div>
<div id="footer">
  <p>Copyright © 1999-2008 by Digital Mars ®, All Rights Reserved.</p>
  <p>Page generated by <a href="http://code.google.com/p/dil">dil</a> on Sun Dec 28 04:26:44 2008. Rendered by <a href="http://code.google.com/p/dil/wiki/Kandil">kandil</a>.</p>
</div>
</body>
</html>